
/**
 * 指令类型（insert： 曾、Remove：删、Copy：复制、Cut：剪切、Past：粘贴、Clear：清空、ClearSketchpad：清空所有线条）
 * @type {{Insert: string, Remove: string, Copy: string, Cut: string, Past: string, Clear: string, ClearSketchpad: string}}
 */
const CommandType = {
    Insert: 'insert',
    Remove: 'remove',
    Update: 'update',
    Copy:   'copy',
    Cut:    'cut',
    Past:   'past',
    Clear:  'clear',
    ClearSketchpad:  'clear-sketchpad',
};

const CommandTargetType = {
    Sketchpad: 'sketchpad',
    MusicScoreEditor: 'music-score-editor'
};

/**
 * 指令类
 */
class Command {

    static className() {
        return 'Command';
    }

    /**
     * 构造方法
     * @param target
     * @param type
     * @param targetType
     */
    constructor(target, type, targetType) {
        this._target = target;
        this._type = type;
        this._targetType = targetType;
    }

    /**
     * 指令类型
     * @returns {*}
     */
    get type() {
        return this._type;
    }

    /**
     * 当前指令目标元素
     * @returns {*}
     */
    get target() {
        return this._target;
    }

    get targetType() {
        return this._targetType;
    }

    get operateType() {
        return this._operateType;
    }

    set operateType(value) {
        this._operateType = value;
    }

    get extra() {
        if (!this._extra) {
            this._extra = {};
        }
        return this._extra;
    }

    set extra(value) {
        this._extra = value;
    }
}

/**
 * 新增指令
 */
class InsertCommand extends Command {

    static className() {
        return 'InsertCommand';
    }

    /**
     * 构造方法
     * @param target
     * @param targetType
     */
    constructor(target, targetType) {
        super(target, CommandType.Insert, targetType);
    }
}
/**
 * 删除指令
 */
class RemoveCommand extends Command {

    static className() {
        return 'RemoveCommand';
    }

    /**
     * 构造方法
     * @param target
     * @param targetType
     */
    constructor(target, targetType) {
        super(target, CommandType.Remove, targetType);
    }
}
/**
 * 更新指令
 */
class UpdateCommand extends Command {

    static className() {
        return 'UpdateCommand';
    }

    /**
     * 构造方法
     * @param target
     * @param targetType
     */
    constructor(target, targetType) {
        super(target, CommandType.Update, targetType);
    }

    /**
     * 原始数据/状态
     * @return {*}
     */
    get originalValue() {
        return this._originalValue;
    }

    set originalValue(value) {
        this._originalValue = value;
    }

    /**
     * 新数据/目标数据
     * @return {*}
     */
    get targetValue() {
        return this._targetValue;
    }

    set targetValue(value) {
        this._targetValue = value;
    }
}
/**
 * 复制指令
 */
class CopyCommand extends Command {

    static className() {
        return 'CopyCommand';
    }

    /**
     * 构造方法
     * @param target
     * @param targetType
     */
    constructor(target, targetType) {
        super(target, CommandType.Copy, targetType);
    }
}
/**
 * 剪切指令
 */
class CutCommand extends Command {

    static className() {
        return 'CutCommand';
    }

    /**
     * 构造方法
     * @param target
     * @param targetType
     */
    constructor(target, targetType) {
        super(target, CommandType.Cut, targetType);
    }
}
/**
 * 粘贴指令
 */
class PastCommand extends Command {

    static className() {
        return 'PastCommand';
    }

    /**
     * 构造方法
     * @param target
     * @param targetType
     */
    constructor(target, targetType) {
        super(target, CommandType.Past, targetType);
    }
}
/**
 * 清空所有线条指令
 */
class ClearSketchpadCommand extends Command {

    static className() {
        return 'ClearSketchpadCommand';
    }

    /**
     * 构造方法
     * @param target
     */
    constructor(target) {
        super(target, CommandType.ClearSketchpad, CommandTargetType.Sketchpad);
    }
}

module.exports = {
    CommandType,
    CommandTargetType,
    Command,
    InsertCommand,
    RemoveCommand,
    UpdateCommand,
    CopyCommand,
    CutCommand,
    PastCommand,
    ClearSketchpadCommand
};
